//base
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Form, Button } from '@tarojs/components'
import { connect } from '@tarojs/redux'
//less
import './index.less'
import If from '../if'
import messagePush from '../../../util/messagePush'
import { getStorageSync } from '../../../crossplatform/apiservice/storage'
import { getGenderIcon, avater } from '../../../configuration/staticimg'
import scaleImageSrc from '../../../util/pagemethods/scaleImageSrc'

@connect(
  userinfo => ({ ...userinfo }),
  dispatch => ({})
)
class AlumniListItem extends Component {
  constructor(props) {
    super(props)
    this.state = {
      isiPhone: false
    }
  }
  componentWillMount() {
    //onLoad
    // 判断是否是iphone
    this.setState({
      isiPhone: getStorageSync('iPhone')
    })
  }

  componentDidMount() {
    //onready
  }

  componentWillUnmount() {
    //onUnload
  }

  componentWillReceiveProps(nextprops) {}

  formSubmit = e => {
    let { formId } = e.detail
    console.log(e, this.props.userinfo)
    const { openId, userId } = this.props.userinfo
    messagePush.insertFormId({ userId, formId, openId })
  }

  onTap = () => {
    this.props.onTap && this.props.onTap()
  }

  render() {
    const { data, type } = this.props
    const { isiPhone } = this.state
    return (
      <View
        className={`wrap-big ${data.archive_state == 0 && type == 'collection' ? 'unactive' : ''}`}
      >
        <Form onSubmit={this.formSubmit} reportSubmit className="ad-imgs-item">
          <Button
            formType="submit"
            className='alumnisingle form-btn'
            onClick={this.onTap}
          >
            <View className="alumnipic">
              <Image
                className="image-alumnipic"
                mode="aspectFill"
                lazy-load
                src={scaleImageSrc(
                  data.userAvator || avater(data.gender == 'female' ? 'female' : 'male', data.userId || data.id || data.archiveId)
                )}
              />
              <If visible={data.gender == 'male'}>
                <Image className="sexwrap" mode="widthFix" src={getGenderIcon('male')} />
              </If>
              <If visible={data.gender == 'female'}>
                <Image className="sexwrap" mode="widthFix" src={getGenderIcon('female')} />
              </If>
            </View>

            <View
              className={`alumniright ${isiPhone ? '' : 'alumniright-false'}`}
            >
              <View className="al-top">
                <View className="name">{data.userName}</View>
                {data.workNature && data.workNature.length
                  ? data.workNature.map((dataWork, indexWork) => {
                      return (
                        <View key={dataWork.id}>
                          <If visible={dataWork == '兼职'}>
                            <Image
                              className="jobtype"
                              mode="widthFix"
                              src="https://imagesize.hrwork.com/sp/files/f0f92fd2-5c5f-4702-88af-2c4bed62db22.png"
                            />
                          </If>
                          <If visible={dataWork == '全职'}>
                            <Image
                              className="jobtype"
                              mode="widthFix"
                              src="https://imagesize.hrwork.com/sp/files/6b18b1a7-0b04-4cea-85a3-0beb34cc0a89.png"
                            />
                          </If>
                          <If visible={dataWork == '实习'}>
                            <Image
                              className="jobtype"
                              mode="widthFix"
                              src="https://imagesize.hrwork.com/sp/files/6e26440e-b574-4830-be44-05a487fffe4d.png"
                            />
                          </If>
                        </View>
                      )
                    })
                  : null}
                <View className="unitype">{data.education ? data.education : ''}</View>
              </View>
              <View className="contenttext">
                {data.intro || data.skillDescription || '这家伙很懒,什么都没写'}
              </View>
              <View className="workneedwrap">
                {data.workCategory &&
                  data.workCategory.map((datain, index) => {
                    return datain ? (
                      <View className="workneedsingle" key={index}>
                        #{datain}
                      </View>
                    ) : null
                  })}
                <View className="text-grand" />
              </View>
            </View>
          </Button>
        </Form>
        <If visible={type == 'talentTalk'}>
          <View className="talent-time">
            <View className="text">{data.createTime}</View>
            <View className="white" />
          </View>
        </If>
      </View>
    )
  }
}
AlumniListItem.defaultProps = {
  data: {}
}

export default AlumniListItem
